Jet().$package(function(J){
	var $=J.dom.id,
	$D=J.dom,
	$E=J.event,
	$H=J.http,
	$U=J.ui,
	get,
	post,
	datetime,
	alertMsg,
	showTip;
	
	/**
	 * tool 名字空间
	 * 
	 * @namespace
	 * @name tool
	 */
	J.tool = J.tool || {};
	
	/**
	 * datetimet方法
	 * 
	 * @memberOf tool
	 * @method	get
	 * @param {int} time 时间戳
	 * @return {String} 返回日期时间，格式：'yyyy-MM-dd hh:mm:ss'
	 */
	datetime = function(time){
		var oDate = new Date();
		oDate.setTime(time+'000');
		return J.formatDate(oDate, 'yyyy-MM-dd hh:mm:ss');
	};
		
	/**
	 * get方法
	 * 
	 * @memberOf tool
	 * @method	get
	 * @param {String} uri uri地址
	 * @param {Fucntion} callback 回调函数
	 * @param {String} type 返回数据类型 json/text/xml/script
	 * @param {boolean} isAsync 是否同步
	 * @return {Object} ajax 返回一个ajax对象，可以abort掉
	 */
	get = function(uri, callback, type, isAsync){
		var options = {
			method: 'GET',
			arguments: { 'callback': callback },
			onSuccess: ajaxSuccess,
			onError: ajaxError,
			type: type || 'json',
			isAsync: (isAsync==undefined ? true : isAsync)
		};
		return $H.ajax(uri, options);
	};
	
	/**
	 * post方法
	 * 
	 * @memberOf tool
	 * @method	get
	 * @param {String} uri uri地址
	 * @param {Object} data 数据对象
	 * @param {Fucntion} callback 回调函数
	 * @param {String} type 返回数据类型 json/text/xml/script
	 * @param {boolean} isAsync 是否同步
	 * @return {Object} ajax 返回一个ajax对象，可以abort掉
	 */
	post = function(uri, data, callback, type, isAsync){
		var options = {
			method: 'POST',
			data: data,
			arguments: { 'callback': callback },
			onSuccess: ajaxSuccess,
			onError: ajaxError,
			contentType: 'application/x-www-form-urlencoded',
			type: type || 'json',
			isAsync: (isAsync==undefined ? true : isAsync)
		};
		return $H.ajax(uri, options);
	};
	
	// Ajax请求成功
	function ajaxSuccess(o){
		var response = o.response;
		if(response.ikylin!=undefined) {
			alertMsg(response.ikylin);
		} else {
			o.arguments.callback(response);
		}
	}
	
	//Ajax请求失败
	function ajaxError(o){
		alertMsg('由于网络原因，请求失败');
	}
	
	/**
	 * 弹窗提示
	 * @memberOf tool
	 * @method	alertMsg
	 * @param {String} message 显示的内容
	 * @param {String} title 标题
	 * @return void
	 */
	alertMsg = function(message, title) {
		var msgDiv = $D.node('div', {'class':'dialog-message'});
		var msgSpan = $D.node('span');
		$D.text(msgSpan, message);
		$D.html(msgDiv,msgSpan);
		var title = title==undefined ? '提示' : title;
		$U.msgDialog = new $U.Dialog({'divNode':msgDiv, 'title':title, 'width':'200px', 'isDrag':false, 'isRemove':true});
		$U.msgDialog.show();
	};
	
	J.tool.confirm = function(message, callback) {
		var dConfirm = $D.node('div', {'class':'dialog-confirm'});
		
		var dMessage = $D.node('em');
		$D.text(dMessage, message);
		dConfirm.appendChild(dMessage);
		
		var dButtons = $D.node('div', {'class':'form-button'});
		
		var dSure = $D.node('a', {'href':'javascript:void(0);', 'class':'button-blue'});
		var dSureSpan = $D.node('span');
		$D.text(dSureSpan, '确定');
		dSure.appendChild(dSureSpan);
		dButtons.appendChild(dSure);
		
		var dCancel = $D.node('a', {'href':'javascript:void(0);', 'class':'button-grey'});
		var dCancelSpan = $D.node('span');
		$D.text(dCancelSpan, '取消');
		dCancel.appendChild(dCancelSpan);
		dButtons.appendChild(dCancel);
		
		dConfirm.appendChild(dButtons);
		
		var oDialog = new $U.Dialog({'divNode':dConfirm, 'title':'确认', 'width':'240px', 'isLayer':true, 'isDrag':false, 'isRemove':true});
		$E.on(dSure, 'click', function(){
			callback();
			oDialog.hide();
		});
		$E.on(dCancel, 'click', function(){ oDialog.hide(); });
		oDialog.show();
	};
	
	/**
	 * 操作成功提示
	 * @memberOf tool
	 * @method	alertTip
	 * @param {String} tip 提示
	 * @return void
	 */
	showTip = function(tip) {
		var tipSpan = $('tip_span');
		var tipDiv = tipSpan.parentNode;
		$D.text(tipSpan, tip);
		$D.show(tipDiv);
		var t = setTimeout(function(){
			$D.hide(tipDiv);
			clearTimeout(t);
		}, 1200);
	};
	
	/**
	 * 按钮加载效果
	 */
	J.tool.oButtons = {};
	J.tool.disableButton = function(id) {
		var dButton = $(id),
			oButtons = J.tool.oButtons,
			oButton = {};
		if(oButtons[id]!=undefined) return;
		oButton.href = dButton.href;
		oButton.className = dButton.className;
		oButton.inner = dButton.innerHTML;
		oButtons[id] = oButton;
		dButton.href = 'javascript:void(0);';
		dButton.className = 'button-disable';
		dButton.innerHTML = '<span><em class="button-loading">提交中...</em></span>';
	};	
	J.tool.activeButton = function(id) {
		var dButton = $(id),
			oButtons = J.tool.oButtons,
			oButton = oButtons[id];
		if(oButton==undefined) return;
		dButton.href = oButton.href;
		dButton.className = oButton.className;
		dButton.innerHTML = oButton.inner;
		delete oButtons[id];
	};
	
	J.tool.datetime = datetime;
	J.tool.get = get;
	J.tool.post = post;
	J.tool.alertMsg = alertMsg;
	J.tool.showTip = showTip;
	
});